package com.zye.controller;

import com.alibaba.fastjson2.JSON;
import com.zye.entity.ResponseResult;
import com.zye.entity.Student;
import com.zye.service.StudentService;
import com.zye.service.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addStudent")
public class addStudent extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        resp.setContentType("application/json;charset=utf-8");
        String name = req.getParameter("name");
        int age = Integer.parseInt(req.getParameter("age"));
        String gender = req.getParameter("gender");
        String address = req.getParameter("address");
        String idcard = req.getParameter("idcard");
        StudentService service = new StudentServiceImpl();
        service.addStudent(new Student(name, age, gender, address, idcard));
        ResponseResult result = new ResponseResult(200,"添加成功",null);
        resp.getWriter().write(JSON.toJSONString(result));
    }
}
